package ee.ttu.controller;

import ee.ttu.model.Ettepanek;
import ee.ttu.model.Oppejoud;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.ui.Model;

import ee.ttu.frontend.service.WishService;




import java.util.List;


/**
 * Created by Julia on 4/27/2015.
 */

@RestController
public class WishController {
	
	final static Logger logger = Logger.getLogger(WishController.class);
	
    @Autowired
    WishService wishService;

    @RequestMapping(value = "/getwish", method = RequestMethod.GET,produces = "application/json")
    public @ResponseBody Ettepanek getSoov(@RequestParam long wishId) {
    	logger.info("Invoking getwish: " + wishId);
    	
        Ettepanek ettepanek = wishService.getSoov(wishId);
        return ettepanek;
    }


    @RequestMapping(value = "/getwishes", method = RequestMethod.GET,produces = "application/json")
    public @ResponseBody List<Ettepanek> getSoovid(){
    	logger.info("Invoking getwishes");
    	
        List<Ettepanek> ettepanek = wishService.getSoovid();
        return ettepanek;

    }

    @RequestMapping(value = "/getteacherwishes", method = RequestMethod.GET,produces = "application/json")
    public @ResponseBody List<Ettepanek> getOppejouSoovid(@RequestParam long teacherId){
    	logger.info("Invoking getteacherwishes: " + teacherId);
    	
        List<Ettepanek> ettepanek = wishService.getOppejouSoovid(teacherId);
        return ettepanek;
    }
    
    @RequestMapping(value = "/acceptwish", method = RequestMethod.PUT)
	public @ResponseBody void acceptWish(@RequestParam long wishId,@RequestParam String teacherUsername,Model model){
    	logger.info("Invoking acceptwish: Wish Id = " + wishId +" username: " + teacherUsername);
    	
		wishService.acceptWish(teacherUsername,wishId,model);
	}
	
	@RequestMapping(value = "/declinewish", method = RequestMethod.PUT)
	public @ResponseBody void declineWish(@RequestParam long wishId,@RequestParam String teacherUsername,Model model){
		logger.info("Invoking declinewish: Wish Id = " + wishId +" username: " + teacherUsername);
		
		wishService.declineWish(teacherUsername, wishId, model);
	}


	@RequestMapping(value = "/deactivatewish", method = RequestMethod.PUT)
	public @ResponseBody void deactivateWish(@RequestParam long wishId,@RequestParam String studentUsername,Model model){
		logger.info("Invoking deactivatewish: Wish Id = " + wishId +" username: " + studentUsername);
		
		wishService.deactivateWish(studentUsername, wishId, model);

	}
	
	@RequestMapping(value = "/activatewish", method = RequestMethod.PUT)
	public @ResponseBody void activateWish(@RequestParam long wishId,@RequestParam String studentUsername,Model model){
		logger.info("Invoking activatewish: Wish Id = " + wishId +" username: " + studentUsername);
		
		wishService.activateWish(studentUsername, wishId, model);
	}
	
	@RequestMapping(value = "/createwish", method = RequestMethod.POST)
	public @ResponseBody void createWish(@RequestParam String title,@RequestParam String description,@RequestParam String topicCode,@RequestParam String studentUsername,@RequestParam String teacherUsername, Model model){
		logger.info("Invoking createwish: Ettepanek=");
		
		wishService.createWish(title,description,topicCode,studentUsername,teacherUsername, model);
	}
	@RequestMapping(value = "/changewish", method = RequestMethod.POST)
	public @ResponseBody void changeWish(@RequestParam long wishId,@RequestParam String title,@RequestParam String description,@RequestParam String studentUsername, Model model){
		logger.info("Invoking changewish: Ettepanek= ");
		
		wishService.changeWish(wishId,title,description,studentUsername,model);
	}
}
